package listeners;

import gui.panel.ConversationPanel;
import gui.panel.HomePanel;
import gui.panel.MainTabs;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.DefaultListModel;
import javax.swing.JList;


public class NewConversationListener implements MouseListener {

	private MainTabs mainTabs;
	
	public NewConversationListener(MainTabs mainTabs) {
		this.mainTabs = mainTabs;
	}
	


	@Override
	public void mouseClicked(MouseEvent mouseEvent) {
		// TODO Auto-generated method stub
		JList listConnectedUsers = (JList) mouseEvent.getSource();
		if (mouseEvent.getClickCount() == 2) {
			int index = listConnectedUsers.locationToIndex(mouseEvent.getPoint());
			if (index >= 0) {
				String nickname = (String) listConnectedUsers.getModel().getElementAt(index);
				if(!this.mainTabs.conversationExists(nickname))
					this.mainTabs.addNewConversation(nickname);
				this.mainTabs.focusOnTab(nickname);
			}
		}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
